<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2020/05/20
 * Time: 18:12
 */
 
namespace HiCommon\Repository;

use Illuminate\Support\Facades\DB;
class ViewFinanceCouponRepository extends BaseRepository
{
    public function base_model(){
        return new \HiCommon\Model\ViewFinanceCoupon();
    }

    /*优惠券津贴结算-按商户统计*/
    public function account_settle($arr_where){
        $arr_select    = [DB::raw('sum(settle_money) as sum_settle_money')];
        $result           = self::base_model()
                                ->where($arr_where)
                                ->groupBy('shop_id')
                                ->get($arr_select);
        return $result;
    }

    /*优惠券津贴结算-按商户统计-不可结算*/
    public function account_settle_can_not($arr_where = []){
        $arr_where['is_settle'] = 2;
        $arr_where['is_finish'] = 2;
        return self::account_settle($arr_where);
    }

    /*优惠券津贴结算-按商户统计-可结算*/
    public function account_settle_can($arr_where = []){
        $arr_where['is_finish'] = 1;
        $arr_where['is_settle'] = 2;
        return self::account_settle($arr_where);
    }

    /*优惠券津贴结算-按商户统计-已结算*/
    public function account_settle_already($arr_where = []){
        $arr_where['is_settle'] = 1;
        $arr_where['is_finish'] = 1;
        return self::account_settle($arr_where);
    }

    /*账户结算-数据列表*/
    public function account_settle_list($arr_where = [],$arr_option = []){
        $result           = self::base_model()
                                ->where($arr_where)
                                ->getoption($arr_option)
                                ->get();
        return $result;
    }

    /*账户结算-数据列表-可结算*/
    public function account_settle_list_can($arr_where = [],$arr_option = []){
        $arr_where['is_finish'] = 1;
        $arr_where['is_settle'] = 2;
        $arr_option['field'] = ['id','settle_money'];
        return self::account_settle_list($arr_where,$arr_option);
    }



}